﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BBCP.Model;

namespace BBCP.UI.Tasks
{
    public class GetBestDiscount : ITask
    {
        public bool Run()
        {
            using (var context = new NorthwindEntities())
            {
                var query = (from o in context.Order_Details.AsEnumerable()
                             join p in context.Products.AsEnumerable() on o.ProductID equals p.ProductID
                             select
                                  new
                                  {
                                      ProductName = p.ProductName,
                                      Discount = o.UnitPrice * (decimal)o.Discount
                                  }).OrderByDescending(n => n.Discount).Take(10);

                foreach (var item in query)
                {
                    Console.WriteLine("Product name: {0} | Discount: {1}", item.ProductName, item.Discount);
                }
            }
            return true;
        }
    }
}
